<!-- <template>
    <header class="header">
        <nav class="nav">
            <div class="nav-container">
                <a href="/" class="logo">
                    <img src="https://flowbite.com/docs/images/logo.svg" class="logo-img" alt="Flowbite Logo" />
                    <span class="blog-name">
                        {{ $store.state.setting.blogName }}
                    </span>
                </a>
                <div class="user-section">
                    <span class="login-btn" v-if="isLogin == false" 
                        @click="$router.push('/login')">登录</span>
                    <button type="button" v-else
                        class="user-menu-btn"
                        id="user-menu-button" aria-expanded="false" data-dropdown-toggle="user-dropdown"
                        data-dropdown-placement="bottom">
                        <span class="sr-only">Open user menu</span>
                        <img class="avatar" :src="$store.state.setting.avatar" alt="user photo">
                    </button>
                    
                    <div class="dropdown-menu" id="user-dropdown">
                        <ul class="menu-list">
                            <li>
                                <a @click="$router.push('/admin')" class="menu-item">
                                    进入后台
                                </a>
                            </li>
                            <li>
                                <a @click="logout" class="menu-item">
                                    退出登录
                                </a>
                            </li>
                        </ul>
                    </div>
                    <button data-collapse-toggle="navbar-user" type="button"
                        class="mobile-menu-btn"
                        aria-controls="navbar-user" aria-expanded="false">
                        <span class="sr-only">Open main menu</span>
                    </button>
                </div>
                <div class="nav-menu" id="navbar-user">
                    <ul class="menu-list">
                        <li>
                            <a @click="$router.push('/')" :class="['menu-link', currPath == '/' ? 'active' : '']">首页</a>
                        </li>
                        <li>
                            <a @click="$router.push('/category')" 
                               :class="['menu-link', currPath == '/category' ? 'active' : '']">分类</a>
                        </li>
                        <li>
                            <a @click="$router.push('/tag')"
                               :class="['menu-link', currPath == '/tag' ? 'active' : '']">标签</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>
</template>

<script setup>
import { useStore } from 'vuex'
import { useRoute } from 'vue-router';
import { ref } from 'vue';
import { showModel, showMessage } from '@/composables/util'
import { onMounted } from 'vue'
import { initDropdowns, initCollapses } from 'flowbite'

onMounted(() => {
    initCollapses();
    initDropdowns();
})

const store = useStore()
const route = useRoute()

const currPath = ref(route.path)

console.log(store.state.user)
const keys = Object.keys(store.state.user)
console.log('====== keys')
console.log(keys)
const isLogin = ref(keys.length > 0)

function logout() {
    showModel('是否确定要退出登录？').then(() => {
        console.log('登出')
        store.dispatch('logout')
        showMessage('退出登录成功', 'success')
        isLogin.value = false
    }).catch(() => { })
}
</script>

<style scoped>
.header {
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

.nav-container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
}

.logo-img {
    height: 2rem;
    margin-right: 0.75rem;
}

.blog-name {
    align-self: center;
    font-size: 1.5rem;
    font-weight: 600;
    white-space: nowrap;
}

.user-section {
    display: flex;
    align-items: center;
}

.login-btn {
    color: #111827;
    cursor: pointer;
}

.login-btn:hover {
    color: #1d4ed8;
}

.user-menu-btn {
    display: flex;
    margin-right: 0.75rem;
    border-radius: 9999px;
}

.avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
}

.dropdown-menu {
    z-index: 50;
    display: none;
    margin-top: 1rem;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.menu-list {
    padding: 0.5rem 0;
}

.menu-item {
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
}

.menu-item:hover {
    background: #f3f4f6;
}

.mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
}

.nav-menu {
    display: none;
    width: 100%;
}

.menu-link {
    display: block;
    padding: 0.5rem 0.75rem;
    color: #374151;
    cursor: pointer;
}

.menu-link:hover {
    color: #1d4ed8;
}

.menu-link.active {
    color: #1d4ed8;
}

@media (min-width: 768px) {
    .mobile-menu-btn {
        display: none;
    }
    
    .nav-menu {
        display: flex;
        width: auto;
    }
    
    .menu-list {
        display: flex;
        gap: 2rem;
        padding: 0;
    }
    
    .menu-link {
        padding: 0;
    }
}
</style> -->